﻿using FirstFloor.ModernUI.Windows.Controls;
using KinectLibrary;
using KinectLibrary.Debug;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SLA
{
    /// <summary>
    /// Interaction logic for DebugLog.xaml
    /// </summary>
    public partial class DebugLog : Window
    {
        public DebugLog()
        {
            InitializeComponent();
        }
                
        void Logger_ValueReady(string value)
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                var threadId = String.Empty;//System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " - ";
                var split = value.Split('#');
                if (split[0] == "wordsLeft")
                {
                    txtLog.Text = threadId + "Quedan " + split[1] + " palabras para hablar\n" + txtLog.Text;
                    //txtLog.Text = threadId + split[1] + " " + split[2] + " " + split[3] + "\n" + txtLog.Text;
                }
                else if (split[0] == "cost")
                {
                    txtLog.Text = threadId + split[1] + " es el costo reconocido\n" + txtLog.Text;
                }
                else if (split[0] == "skeletonDist")
                {
                    txtLog.Text = threadId + "Estas a " + split[1] + " metros\n" + txtLog.Text;
                }
                else if (split[0] == "movement")
                {
                    txtLog.Text = threadId + split[1] + " es el desfase\n" + txtLog.Text;
                }
                else if (split[0] == "horizontal")
                {
                    txtLog.Text = threadId + split[1] + " desfase horizontal\n" + txtLog.Text;
                }
                else if (split[0] == "vertical")
                {
                    txtLog.Text = threadId + split[1] + " desfase vertical\n" + txtLog.Text;
                }
            }));
        }
        
        private void DebugWindow_Closed(object sender, EventArgs e)
        {
            DebugInfo.DebugWordsLeft = false;
            DebugInfo.DebugCost = false;
            DebugInfo.DebugSkeletonDist = false;
            DebugInfo.DebugMovement = false;
            DebugInfo.DebugHorizontal = false;
            DebugInfo.DebugVertical = false;

            Logger.ValueReady -= Logger_ValueReady;
            //System.Threading.Thread.CurrentThread.Abort();
        }

        private void DebugWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //lblLog.Text += " - " + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
            Logger.ValueReady += Logger_ValueReady;
        }

        private void btnPlay_Click(object sender, RoutedEventArgs e)
        {
            Logger.ValueReady += Logger_ValueReady;
            btnPlay.Visibility = Visibility.Collapsed;
            btnPause.Visibility = Visibility.Visible;
        }

        private void btnPause_Click(object sender, RoutedEventArgs e)
        {
            Logger.ValueReady -= Logger_ValueReady;
            btnPlay.Visibility = Visibility.Visible;
            btnPause.Visibility = Visibility.Collapsed;
        }

        private void chkWordsLeft_Checked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugWordsLeft = true;
        }

        private void chkCost_Checked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugCost = true;
        }

        private void chkSkeletonDist_Checked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugSkeletonDist = true;
        }

        private void chkMovement_Checked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugMovement = true;
        }

        private void chkHorizontal_Checked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugHorizontal =  true;
        }

        private void chkVertical_Checked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugVertical = true;
        }

        private void chkWordsLeft_Unchecked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugWordsLeft = false;
        }

        private void chkCost_Unchecked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugCost = false;
        }

        private void chkSkeletonDist_Unchecked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugSkeletonDist = false;
        }

        private void chkMovement_Unchecked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugMovement = false;
        }

        private void chkHorizontal_Unchecked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugHorizontal = false;
        }

        private void chkVertical_Unchecked(object sender, RoutedEventArgs e)
        {
            DebugInfo.DebugVertical = false;
        }
    }
}
